package cn.fay.chapter17;

import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Random;

public class Utilities {
	static List<String> list=Arrays.asList("one Two three Four five six one".split(" "));
	public static void main(String[] args) {
		System.out.println(list);
		boolean disjoint = Collections.disjoint(list,Collections.singleton("Four"));
		System.out.println("'list' disjoint (Four)?:"+disjoint);
		System.out.println("Max: "+Collections.max(list));
		System.out.println("Min: "+Collections.min(list));
		System.out.println("Max w/ comparator: "+Collections.max(list, String.CASE_INSENSITIVE_ORDER));
		System.out.println("Min w/ comparator: "+Collections.min(list, String.CASE_INSENSITIVE_ORDER));
		List<String> sublist=Arrays.asList("Four five six".split(" "));
		System.out.println("indexOfSublist: "+Collections.indexOfSubList(list, sublist));
		System.out.println("lastIndexOfSublist: "+Collections.lastIndexOfSubList(list, sublist));
		Collections.replaceAll(list, "one", "Yo");
		System.out.println("replaceAll: "+list);
		Collections.reverse(list);
		System.out.println("reverse: "+list);
		Collections.rotate(list, 3);
		System.out.println("rotate: "+list);
		List<String> source=Arrays.asList("in the matrix".split(" "));
		Collections.copy(list, source);
		System.out.println("copy: "+list);
		Collections.swap(list, 0, list.size()-1);
		System.out.println("swap: "+list);
		Collections.shuffle(list, new Random());
		System.out.println("shuffle: "+list);
		Collections.fill(list, "pop");
		System.out.println("fill: "+list);
		int frequency = Collections.frequency(list, "pop");
		System.out.println("frequency of 'pop': "+frequency);
		List<String> dups = Collections.nCopies(3, "snap");
		System.out.println("dups: "+dups);
		disjoint = Collections.disjoint(list, dups);
		System.out.println("list disjoint 'dups'?: "+disjoint);
	}
}
